% /*******************************************************************************
%  * Main Simulation Routine
%  * *****************************************************************************
%  * @param lower
%  * @param upper
%  * @param m
%  * @param n
%  * @param r
%  * @param k
%  * @param q
%  * @param t
%  * @param z
%  */
function avg_err = get_ev(lower,upper,m,n,r,k,f, p)

step_a = 2^(-m);
step_b = 2^(-n);
avg_err = 0.0;

for a = lower:step_a:upper
    ia = floor((a - lower)/step_a) + 1;
    for b = lower:step_b:upper
        ib = floor((b-lower)/step_b) + 1;
        ans_true = a * b;
        ans_trunc = trunc_mult(a,b,f,m,n,r,k);              
        err = abs(ans_true - ans_trunc);
        weight_err = err * p(ia) * p(ib);
        avg_err = avg_err + weight_err;
    end
end

end